package com.bdcom.autotest.interaction.testins;
import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;



import java.nio.charset.Charset;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.bdcom.autotest.interaction.bean.NXCARDINFO;
import com.sun.jna.IntegerType;
import com.sun.jna.Library;
import com.sun.jna.Memory;
import com.sun.jna.Native;
import com.sun.jna.Pointer;
import com.sun.jna.ptr.IntByReference;
import com.sun.jna.ptr.PointerByReference;

public class JnaTest {
    public interface DllInterface extends Library {
    	DllInterface INSTANCE = (DllInterface) Native.loadLibrary("NXATT", DllInterface.class);// 动态库实例
//    	DllInterface INSTANCE2 = (DllInterface) Native.loadLibrary("NxTechAPI", DllInterface.class);// 动态库实例
//    	DllInterface INSTANCE3 = (DllInterface) Native.loadLibrary("Protocol", DllInterface.class);// 动态库实例
    	boolean startTest();
//    	boolean NXConnectChassis( byte  ip0,  byte  ip1,  byte  ip2, byte  ip3,IntByReference nChassisNo);
//    	boolean NXDisConnectChassis(int nChassisNo);
//    	int NXGetCardCnt(int nChassisNo);
//    	int NXGetSvrStatus(int nChassisNo);
//    	int NXGetPortCount(int nChassisNo, int nCardNo);// 获取端口个数
//    	NXCARDINFO.ByValue NXGetCardInfo(int nChassisNo, int nCardNo);//板卡信息结构体
//    	int NXGetPortStatus(int nChassisNo, int nCardNo, int nPortNo);//获取端口状态信息
//    	boolean NXRequestNxPort(int nChassisNo, int nCardNo, int nPortNo);//申请端口
//    	boolean NXStartConfig(int nChassisNo, int nCardNo, int nPortNo);//开始配置
//    	boolean ReleaseNxPort(int nChassisNo,int nCardNo,int nPortNo);//释放端口
//    	boolean NXSetNetWorker(int nChassisNo,int nCardNo, int nPortNo, int nSpeedType, int nSpeed, int nNetMode);
//    	boolean NXResetAllDevice(int nChassisNo,int nCardNo);//整机复位
//    	boolean NXResetPort(int nChassisNo, int nCardNo, int nPortNo,int nType);//端口复位
//    	boolean NXZeroStatistics(int nChassisNo, int nCardNo, int nPortNo);//清空统计信息
//    	int  NXGetCardMode(int nChassisNo,int nCardNo);
//    	boolean NXSetCardMode(int nChassisNo,int nCardNo,int nType);
//    	int NXGetCardChangeModeState();
    }

 

    public static void main(String[] args) {
    	 String info="";
    	try{
    		boolean result = false;
    		Process p = Runtime.getRuntime().exec( System.getProperty("user.dir")+"/src/main/resources/NXATT.exe");
    		BufferedReader buf = new BufferedReader(new InputStreamReader(
					p.getInputStream(),Charset.forName("GBK")));
    		String line=null;
    		while((line=buf.readLine())!=null){
    			//  System.out.println("*******"+line);
    			info = line;
    			System.out.println(info);
    			if(line.indexOf("测试通过")!=-1){
    				result = true;
    			}
    		}
//    		
//    		try {
//				int exitVal=p.waitFor();
//			} catch (InterruptedException e) {
//				// TODO Auto-generated catch block
//				e.printStackTrace();
//			}
		} catch (IOException e) {
			e.printStackTrace();
		} finally{
			//System.out.print(p.exitValue());
		}

		
    }

}